<?php
//根据客户端提交的登录用户名 返回当前登陆用户的购物车详情 型如
/**
	[
	{"pid":10,"pname":"xx","pic":"x.jpg","price":1000,"count":3,"did":1},
	{"pid":15,"pname":"xx","pic":"x.jpg","price":1000,"count":1,"did":2},
	{"pid":18,"pname":"xx","pic":"x.jpg","price":1000,"count":2,"did":3},
	]
**/
header('Content-Type:application/json;charset=utf-8');
@$uname=$_REQUEST['uname'] or die('{"msg":"err","reason":"uname required"}');

require('0_init.php');

//根据用户名 查询出用户编号
$sql="SELECT uid FROM jd_user WHERE uname='$uname'";
$result=mysqli_query($conn,$sql);
$row=mysqli_fetch_row($result);
if($row){
	$uid=$row[0];
}else{
	die('{"msg":"err","reason":"uname non-exists"}');
}
//根据用户编号 查询 购物车编号
$sql="SELECT cid FROM jd_cart WHERE userId='$uid'";
$result=mysqli_query($conn,$sql);
$row=mysqli_fetch_row($result);
if($row){//有购物车
	$cid=$row[0];
}else{//无购物车
	die("[]");
}
//根据购物车编号 查询出商品购买详情 跨表查询
$sql="SELECT pid,pname,pic,price,count,did FROM jd_cart_detail,jd_product WHERE pid=productId AND cartId='$cid'";
$result=mysqli_query($conn,$sql);
$list=mysqli_fetch_all($result,1);
echo json_encode($list);